package com.itheima03;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

/*
* 简单聊天室
* */
public class SendDemo {
    public static void main(String[] args) throws IOException {
        // 创建发送端 socket
        DatagramSocket ds = new DatagramSocket();

        // 自己封装的键盘输入数据
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            // 输入 886，结束
            if ("886".equals(line)) {
                break;
            }

            // 创建数据包
            byte[] bytes = line.getBytes();
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("127.0.0.1"), 12345);

            // 发送
            ds.send(dp);
        }

        // 关闭
        ds.close();
    }
}
